package com.hockeo.server.servlet.convert;

import java.util.ArrayList;
import java.util.List;

import com.hockeo.client.model.JSData;
import com.hockeo.server.data.DAO;

/**
 * Converts server side Java entities into client side GWT entities.
 *
 * @version $Id$
 * @author jjanke
 */
public class J2GwtConverter
{
  private final DAO d_dao;

  /**
   * Creates a new J2GwtConverter.
   *
   * @param dao the DAO object to be used for communicating with the datastore
   */
  J2GwtConverter( DAO dao )
  {
    d_dao = dao;
  }

  public JSData convert( GwtEnabled src )
  {
    JSData dest = new JSData( src.getClass().getName() );

    src.toGwt( dest, d_dao, "" );

    return dest;
  }

  public List<JSData> convert( List<? extends GwtEnabled> listSrc )
  {
    List<JSData> listDest = new ArrayList<JSData>();

    for ( GwtEnabled src : listSrc )
      listDest.add( convert( src ) );

    return listDest;
  }
}
